		function process_search (ui,page) {
			var terms = ui.item ? ui.item.value : $('#query').val();
			var sBy = $('input:radio[name=searchBy]:checked').val();
            if ($('#temp').val()=='1') {
                var extra = '&temp=1';
                var urlstr = '/rise/tools2/search.php?q='+escape(terms)+'&type='+sBy+'&page='+page+extra;
            }
            else { var urlstr = '/rise/tools2/search.php?q='+escape(terms)+'&type='+sBy+'&page='+page; }
            //update(1);return false;
			$('#rise-search-results').hide();
			$('#loading').show();
			$.ajax({
				url: urlstr,
				success: function(data) {
					$('#rise-search-results').show().html(data);
                    $('#query').blur();
                    $('#loading').hide();
                    $('html,body').animate({scrollTop: $('#search-results').offset().top},'slow');
                    $('#search-results').focus();
					$('#results-breadcrumb').show();
					$('#results-breadcrumb').html('Search results');
				}
			});
		}
        function show_restriction() {
            alert('You do not have the appropriate permissions to view this article.\nArticles can be viewed by Open University Staff & Students Only');
        }
		function process_rating() {
            $('#rate').hide();
			$('#send-rating-loading').show();
			$.ajax({
				url:'/rise/rating.php?type='+escape($('#relationship_type').val())+'&id1='+escape($('#relationship_id1').val())+'&id2='+escape($('#relationship_id2').val())+'&rating='+$('input:radio[name=rate1]:checked').val(),
				success: function(data) {
					$('#send-rating-loading').hide();
					$('#send-rating-status').html('Rating Received - Thank You');
                    $('#rise-rating').delay(1000).fadeOut('slow');
				}
			});
		}
		function rise_reset_rating() {
			$('#rate').show();
            $('input[name=rate1]:checked').attr('checked',false);
            $('#send-rating-status').html('');
		}
	    $(function() { 
            $('#pagination > a').live('click',function(e) { e.preventDefault(); if ($(this).attr('id')>0) { process_search('',$(this).attr('id')); } $('html,body').animate({scrollTop:0},''); });
			$('#rise-rating-form').live('submit', function(e) { e.preventDefault(); process_rating(); });
			$('#rise-search-form').live('submit', function(e) {	e.preventDefault(); process_search('',1); });
			$('#query').autocomplete({
				source: '/rise/tools2/search_suggest.php',minLength: 0,
				select: function(event,ui ) { process_search(ui,1); }
			});
			$('#rate').buttonset();
            $('#rate').live('click',function(){process_rating();});
            $('.course-rec').live('click', function(){
                if ($(this).attr('risedisabled')!='true') {
                    rise_reset_rating();
                    $('#relationship_type').val('course'); $('#relationship_id1').val($(this).attr('id'));
                    $('#rise-rating').fadeIn('slow');
                    window.scroll(0,0);
                } else { show_restriction(); }
            });
            $('.rel-rec').live('click',function(){
                if ($(this).attr('risedisabled')!='true') {
                    rise_reset_rating();
                    $('#relationship_type').val('rel'); $('#relationship_id1').val($(this).attr('id')); $('#relationship_id2').val($(this).attr('lvid'));
                    $('#rise-rating').fadeIn('slow');
                    window.scroll(0,0);
                } else { show_restriction(); }
            });
            $('.search-rec').live('click',function(){
                if ($(this).attr('risedisabled')!='true') {
                    rise_reset_rating();
                    $('#relationship_type').val('search'); $('#relationship_id1').val($(this).attr('id')); $('#relationship_id2').val($(this).attr('searchid'));
                    $('#rise-rating').fadeIn('slow');
                    window.scroll(0,0);
                } else { show_restriction(); }
            });
            $('.search-result').live('click',function(){
                if ($(this).attr('risedisabled')=='true'){
                    show_restriction();
                }
            });
            $('#close').live('click',function() {
                rise_reset_rating();
                $('#rise-rating').hide();
            });
            $('#new-search').live('click',function(){
                $('#rise-search-results').hide();
                $('#query').val(''); $('#query').focus();
            });
            $('.course-rec,.rel-rec,.search-rec').live('click',function(e) {
                _gaq.push(['_trackEvent','Viewing Article',$(this).attr('rank'),$(this).attr('class')]);
            });
		});